package com.tomshushu.doc.freedoc.modular.user.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.tomshushu.doc.freedoc.core.model.response.ResponseData;
import com.tomshushu.doc.freedoc.core.model.response.SuccessResponseData;
import com.tomshushu.doc.freedoc.modular.project.model.result.ProjectListResult;
import com.tomshushu.doc.freedoc.modular.user.model.param.AddUserParam;
import com.tomshushu.doc.freedoc.modular.user.model.param.GetProjectByTeamIdParam;
import com.tomshushu.doc.freedoc.modular.user.model.param.LoginParam;
import com.tomshushu.doc.freedoc.modular.user.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/doc/user")
public class UserController {

    @Resource
    private UserService userService;

    @PostMapping("/addUser")
    public ResponseData addUser(@RequestBody AddUserParam param) {
        return new SuccessResponseData(userService.addUser(param));
    }
    // TODO 修改用户信息


    /**
     * 登录
     * @param param
     * @return
     */
    @PostMapping("/login")
    public ResponseData login(@RequestBody LoginParam param) {
        return new SuccessResponseData(userService.login(param));
    }
    /**
     * 登出
     * @return
     */
    @PostMapping("/logout")
    public ResponseData logout() {
        userService.logout();
        return new SuccessResponseData();
    }
    /**
     * 检查登录
     * @return
     */
    @PostMapping("/checkLogin")
    public ResponseData checkLogin() {
        return new SuccessResponseData(StpUtil.isLogin());
    }
    /**
     * 获取用户信息
     * @return
     */
    @PostMapping("/userInfo")
    public ResponseData userInfo() {
        return new SuccessResponseData(userService.userInfo());
    }
    /**
     * 获取项目列表
     * @param param
     * @return
     */
    @PostMapping("/getProjectListByUserIdOrTeamId")
    public ResponseData getProjectListByUserIdOrTeamId(@RequestBody GetProjectByTeamIdParam param) {
        return new SuccessResponseData(userService.getProjectListByUserIdOrTeamId(param));
    }

}